package com.electric.qrapp.net.encrypt;

import android.text.TextUtils;
import android.util.Base64;

/**
 * @author created by WA03675
 * @date 2021-12-23 15:08
 * @des
 */
public class DataSecretUtil {
    public static String encrypt(String dataStr, String seed) {
        if (dataStr==null)return null;
        try {
            byte[] seedBytes = seed.getBytes("utf-8");
            byte[] dataBytes = dataStr.getBytes("utf-8");
            byte[] encryptedDate = AesUtil.mCbcEncrypt(dataBytes, seedBytes);
            return Base64.encodeToString(encryptedDate,Base64.NO_PADDING);
//            return Base64.encodeBase64String(encryptedDate)
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public  static String decrypt(String dataStr, String seed) {
        if (TextUtils.isEmpty(dataStr))return null;
        try {
            byte[] seedBytes = seed.getBytes("utf-8");
            byte[] dataBytes = Base64.decode(dataStr,Base64.NO_PADDING);
//            byte[] dataBytes = Base64.decodeBase64(dataStr)
            dataBytes = AesUtil.mCbcDecrypt(dataBytes, seedBytes);
            return new String(dataBytes, "utf-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
} 
